// @ts-ignore
/* eslint-disable */
import {request} from 'umi';
import {PostBody, PostListItem} from './data';

export async function postList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  }, sorter: any,) {
  return request<{
    data: PostListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/v2/enterprise/post/list', {
    method: 'GET',
    params: {
      ...params,
      pageNum: params.current,
      // orderByColumn: "postSort",
      // isAsc: 'desc'
      orderByColumn: Object.keys(sorter)[0],
      isAsc: Object.values(sorter)[0],
    },
  });
}

export async function loadPost(param: { postId?: number }): Promise<{ data: PostBody }> {
  console.log(param)
  return request(`/v2/enterprise/post/${param.postId}`, {method: "GET"});
}

export async function addPost(param: PostBody): Promise<{ data: number }> {
  return request('/v2/enterprise/post', {method: "POST", data: param});
}

export async function updatePost(param: PostBody): Promise<{ data: number }> {
  return request('/v2/enterprise/post', {method: "PUT", data: param});
}

export async function removePost(data: number[], options?: { [key: string]: any }) {
  return request<Record<string, any>>(`/v2/enterprise/post`, {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}

export async function loadPostSelect() {
  return request(`/v2/enterprise/post/select`, {method: "POST"});
}
